<%@ Page Language="VB" MasterPageFile="~/WebForm/SpectrumMasterPage.master" AutoEventWireup="false"
    CodeFile="ChannelSkuType.aspx.vb" Inherits="WebForm_ManageSOSalesForecast_ChannelSkuType"
    Title="Channel Sku Data" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <script type="text/javascript">
        if ($get('CSku_Spreadsheet1') != undefined)
        {
            $get('CSku_Spreadsheet1').activeSheet.protection.enabled = false;
            $get('CSku_Spreadsheet1').activeSheet.cells.locked = true;
            $get('CSku_Spreadsheet1').activeSheet.protection.enabled = true;
        }
    </script>
    <script type="text/vbscript">
        Sub CSku_Spreadsheet1_LoadCompleted()
            set sheet = document.getElementById("CSku_Spreadsheet1")
            sheet.ActiveSheet.Columns.AutoFit()
        End Sub
    </script>

    <table align="center" width="99%" border="0" cellspacing="0">
        <tr>
            <td align="center" colspan="2" height="20px" Class="purple">
                <asp:label id="lblChannelSkuType" SkinID="title" font-size="20px" font-bold="true" runat="server"
                    meta:resourcekey="lblChannelSkuType"></asp:label>(<%=Me.SkuTypeText%>)
                <br />
            </td>
        </tr>
        <tr style="display:none">
            <td align="left">
                <asp:label id="label1" runat="server" meta:resourcekey="lblSkuType"></asp:label>
            </td>
            <td align="left">
                <asp:label id="lblSkuType" runat="server"></asp:label>
            </td>
        </tr>
        <tr>
            <td align="left" colspan="2">
                <object id="CSku_Spreadsheet1" classid="CLSID:0002E559-0000-0000-C000-000000000046" width="99%"
                    height="400px" standby="Loading">
                    <param name="DataType" value="XMLURL" />
                    <param name="XMLURL" value="<%= MyObj.xlsUrlChannelSkuType %>" />
                </object>
<script type="text/vbscript">
    Sub CSku_Spreadsheet1_SelectionChange()
        set WorkSheet_SS = document.getElementById("CSku_Spreadsheet1")
        Dim Row 
	    Dim Col
	    MaxCol = WorkSheet_SS.ActiveSheet.UsedRange.Columns.Count 
        MaxRow = WorkSheet_SS.ActiveSheet.UsedRange.Rows.Count 
        sumvalue = 0 
        sumcount = 0 
        colType = "Number"
        for Each Row In WorkSheet_SS.Selection.Rows 
	        if Row.row > MaxRow then 
	            exit for 
            end if 
            for Each Col In WorkSheet_SS.Selection.Columns 
    	        if Col.column > MaxCol then 
 	 	            exit for 
                end if 
                if VarType(WorkSheet_SS.ActiveSheet.Cells(Row.row,Col.column).value)>=2 and VarType(WorkSheet_SS.ActiveSheet.Cells(Row.row,Col.column).value)<=5 then 
                    if sumcount=0 and InStr(WorkSheet_SS.ActiveSheet.Cells(Row.row,Col.column).NumberFormat,"%")<>0 then
                        colType = "Percent"
                    end if
                    if colType = "Percent" then 
                        sumvalue = sumvalue + (WorkSheet_SS.ActiveSheet.Cells(Row.row,Col.column).value * 100)
                    else
                        sumvalue = sumvalue + WorkSheet_SS.ActiveSheet.Cells(Row.row,Col.column).value 
                    end if
                    sumcount = sumcount + 1
                end if 
            next 
        next 

        if sumcount<>0 Then
            if colType = "Percent" then
                avg = Round(sumvalue / sumcount,2)
            else
                avg = Round(sumvalue / sumcount,0)
            end if
        else
            avg = 0
        end if
        if colType = "Percent" then
            window.status = "Average: " & FormatNumber(avg,2) & "%" & "  Count: " & FormatNumber(sumcount,0) & "  Sum: " & FormatNumber(sumvalue,2) & "%"
        else
            window.status = "Average: " & FormatNumber(avg,0) & "  Count: " & FormatNumber(sumcount,0) & "  Sum: " & FormatNumber(sumvalue,0)
        end if
    End Sub 
</script>
            </td>
        </tr>
        <tr align="center">
            <td colspan="2">
                <asp:button id="btnCancel" onclientclick="window.close()" runat="server"
                    meta:resourcekey="btnCancel" />
            </td>
        </tr>
    </table>      
</asp:Content>
